#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

void Swap(int* x, int* y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}
void SelectSort(int* arr, int n)
{
	int begin = 0;
	int end = n - 1;
	while (begin < end)
	{
		int min = begin;
		int max = begin;
		for (int i = begin + 1; i <= end; i++)
		{
			if (arr[i] < arr[min])
			{
				min = i;
			}
			if (arr[i] > arr[max])
			{
				max = i;
			}
		}
		if (max == begin)
			max = min;
		Swap(&arr[min], &arr[begin]);
		Swap(&arr[max], &arr[end]);
		begin++;
		end--;
	}
}

int main()
{
	int a[] = { 1,4,7,2,5,8,3,6,9 };
	int length = sizeof(a) / sizeof(a[0]);
	SelectSort(a, length);
	for (int i = 0; i < length; i++)
	{
		cout << a[i] << " ";
	}

	return 0;
}